﻿//This file is used my the install to create a membertype and membergroup
//for demostration reasons.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.cms.businesslogic.member;
using umbraco.cms.businesslogic.datatype;
using umbraco.cms.businesslogic.propertytype;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic;
using umbraco.cms.presentation;
using umbraco;
using umbraco.presentation.nodeFactory;

namespace osMemberControls
{
    public partial class Install : System.Web.UI.UserControl
    {

        private DataTypeDefinition _textstring, _datepicker, _gender;
                
        protected void Page_Load(object sender, EventArgs e)
        {
            umbraco.BusinessLogic.User u = new umbraco.BusinessLogic.User(0);
            MemberType mt = MemberType.MakeNew(u, "osMember");
            
            DataTypeDefinition[] dtd = DataTypeDefinition.GetAll();

            _textstring = dtd.First(g => g.Text == "Textstring");
            _datepicker = dtd.First(g => g.Text == "Date Picker");
            _gender = dtd.First(g => g.Text == "Gender");

            mt.AddPropertyType(_textstring, "firstName", "First Name");
            mt.AddPropertyType(_textstring, "lastName", "Last Name");
            mt.AddPropertyType(_datepicker, "DOB", "DOB");
            mt.AddPropertyType(_gender, "Gender", "Gender");
            mt.AddVirtualTab("Personal Details");

            mt.Save();
                        
            umbraco.cms.businesslogic.ContentType.TabI tab = mt.getVirtualTabs.First(); 

            foreach (PropertyType pt in mt.PropertyTypes)
            {
                mt.setMemberCanEdit(pt, true);
                mt.setMemberViewOnProfile(pt, true);
                pt.TabId = tab.Id;                
            }

            MemberGroup mg = MemberGroup.MakeNew("osMemberGroup", u);

            mg.Save();
                
        }
    }
}